From f48bcc9a2cf4c3b426f02b7a9843d1c6b245265a Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Wed, 7 Sep 2005 15:53:04 +0000 Subject: [PATCH] Make xenstored bind to domain exception virq directly, instead of via xcs. Signed-off-by: Christian Limpach --- tools/xenstore/xenstored_core.c | 138 +----------------------------- tools/xenstore/xenstored_domain.c | 12 +++ 2 files changed, 16 insertions(+), 134 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index c9cc84b4c3..c43e6372c0 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -51,7 +51,6 @@ #include "xenstored_domain.h" #include "xenctrl.h" #include "xen/io/domain_controller.h" -#include "xcs_proto.h" static bool verbose; LIST_HEAD(connections); @@ -325,7 +324,7 @@ static int destroy_conn(void *_conn) } static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock, - int event_fd, int xcs_fd) + int event_fd) { struct connection *i; int max; @@ -340,9 +339,6 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock, FD_SET(event_fd, inset); if (event_fd > max) max = event_fd; - FD_SET(xcs_fd, inset); - if (xcs_fd > max) - max = xcs_fd; list_for_each_entry(i, &connections, list) { if (i->domain) continue; @@ -1650,125 +1646,6 @@ static void daemonize(void) umask(0); } -static int open_domain_socket(const char *path) -{ - struct sockaddr_un addr; - int sock; - size_t addr_len; - - if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { - goto out; - } - - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, path); - addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1; - - if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) { - goto out_close_sock; - } - - return sock; - - out_close_sock: - close(sock); - out: - return -1; -} - -bool _read_write_sync(int fd, void *data, size_t size, bool do_read) -{ - size_t offset = 0; - ssize_t len; - - while (offset < size) { - if (do_read) { - len = read(fd, data + offset, size - offset); - } else { - len = write(fd, data + offset, size - offset); - } - - if (len < 1) { - if (len == -1 && (errno == EAGAIN || errno == EINTR)) { - continue; - } else { - return false; - } - } else { - offset += len; - } - } - - return true; -} - -#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true) -#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false) - -/* synchronized send/recv strictly for setting up xcs */ -/* always use asychronize callbacks any other time */ -static bool xcs_send_recv(int fd, xcs_msg_t *msg) -{ - bool ret = false; - - if (!write_sync(fd, msg, sizeof(*msg))) { - eprintf("Write failed at %s:%s():L%d? Possible bug.", - __FILE__, __FUNCTION__, __LINE__); - goto out; - } - - if (!read_sync(fd, msg, sizeof(*msg))) { - eprintf("Read failed at %s:%s():L%d? Possible bug.", - __FILE__, __FUNCTION__, __LINE__); - goto out; - } - - ret = true; - - out: - return ret; -} - -static void handle_xcs(int xcs_fd) -{ - xcs_msg_t msg; - - if (!read_sync(xcs_fd, &msg, sizeof(msg))) - barf_perror("read from xcs failed!"); - - domain_cleanup(); -} - -static int xcs_init(void) -{ - int ctrl_fd, data_fd; - xcs_msg_t msg; - - ctrl_fd = open_domain_socket(XCS_SUN_PATH); - if (ctrl_fd == -1) - barf_perror("Failed to contact xcs. Is it running?"); - - data_fd = open_domain_socket(XCS_SUN_PATH); - if (data_fd == -1) - barf_perror("Failed to contact xcs. Is it running?"); - - memset(&msg, 0, sizeof(msg)); - msg.type = XCS_CONNECT_CTRL; - if (!xcs_send_recv(ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) - barf_perror("xcs control connect failed."); - - msg.type = XCS_CONNECT_DATA; - if (!xcs_send_recv(data_fd, &msg) || msg.result != XCS_RSLT_OK) - barf_perror("xcs data connect failed."); - - msg.type = XCS_VIRQ_BIND; - msg.u.virq.virq = VIRQ_DOM_EXC; - if (!xcs_send_recv(ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) - barf_perror("xcs virq bind failed."); - - return data_fd; -} - static struct option options[] = { { "pid-file", 1, NULL, 'F' }, @@ -1780,7 +1657,7 @@ static struct option options[] = { int main(int argc, char *argv[]) { - int opt, *sock, *ro_sock, event_fd, xcs_fd, max; + int opt, *sock, *ro_sock, event_fd, max; struct sockaddr_un addr; fd_set inset, outset; bool dofork = true; @@ -1864,9 +1741,6 @@ int main(int argc, char *argv[]) /* Listen to hypervisor. */ event_fd = domain_init(); - /* Listen to hypervisor - more. */ - xcs_fd = xcs_init(); - /* Restore existing connections. */ restore_existing_connections(); @@ -1887,8 +1761,7 @@ int main(int argc, char *argv[]) #endif /* Get ready to listen to the tools. */ - max = initialize_set(&inset, &outset, *sock, *ro_sock, event_fd, - xcs_fd); + max = initialize_set(&inset, &outset, *sock, *ro_sock, event_fd); /* Main loop. */ /* FIXME: Rewrite so noone can starve. */ @@ -1919,9 +1792,6 @@ int main(int argc, char *argv[]) if (FD_ISSET(event_fd, &inset)) handle_event(event_fd); - if (FD_ISSET(xcs_fd, &inset)) - handle_xcs(xcs_fd); - list_for_each_entry(i, &connections, list) { if (i->domain) continue; @@ -1965,6 +1835,6 @@ int main(int argc, char *argv[]) unblock_connections(); max = initialize_set(&inset, &outset, *sock, *ro_sock, - event_fd, xcs_fd); + event_fd); } } diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c index 34278ad902..1798b11c09 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -38,6 +38,7 @@ static int *xc_handle; static int eventchn_fd; +static int virq_port; static unsigned int ringbuf_datasize; struct domain @@ -224,6 +225,10 @@ void handle_event(int event_fd) if (read(event_fd, &port, sizeof(port)) != sizeof(port)) barf_perror("Failed to read from event fd"); + + if (port == virq_port) + domain_cleanup(); + #ifndef TESTING if (write(event_fd, &port, sizeof(port)) != sizeof(port)) barf_perror("Failed to write to event fd"); @@ -449,5 +454,12 @@ int domain_init(void) #endif if (eventchn_fd < 0) barf_perror("Failed to open connection to hypervisor"); + + if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port)) + barf_perror("Failed to bind to domain exception virq"); + + if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0) + barf_perror("Failed to bind to domain exception virq port"); + return eventchn_fd; } -- 2.30.2